<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>点击变成红色</title>
  <style>
    .active {
      color: crimson;
    }
  </style>
</head>
<body>
  <div id="app">
    <ul>
      通过对象动态添加class，class里面是对象，bool值，
      当currentindex === index为真的时候，active才有效
      <li v-for="(item, index) in movies" 
      :key="index"
      :class="{active: currentindex === index}"
      @click="liclick(index)">
      {{item}}
    </li>
    </ul>
  </div>

  <script src="../js/vue.js"></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        movies: ['海泽王','火影忍者','海尔兄弟','海王'],
        currentindex: 0     //选中的下标值
      },
      methods: {   //绑定click事件，传递下标值给liclick函数，并更改currentindex为当前下标值
        liclick(index) {
          this.currentindex = index
        }
      },
    })
  </script>
</body>
</html>